tidied by sean :)

Author

Ramon Lorenzo

Published

November 10, 2023

Code
library(tidyverse)
library(ggpubr)
library(ggsci)
library(gt)
library(emmeans)

distance <- read_csv("data/Target cells R21 DISTANCE.csv") |>
  janitor::clean_names(replace=janitor:::mu_to_u) |> 
  mutate(donor = factor(donor),
         replicate = factor(replicate))

Overview + Goals

This document serves to analyze the distance from Thati’s dataset.

Initial Visualization

We can look at this data a few different ways:

Code
distance |>
  ggplot(aes(x= group,
             y= distance_to_annotation_with_epithelium_um,
             color= target_cell)) +
  geom_boxplot(outlier.shape = NA) +
  geom_point(position = position_jitterdodge(), alpha = 0.2) +
  theme_pubr() +
  scale_color_lancet() + 
  facet_grid(tissue*layer~target_cell, scales = "free") +
  rotate_x_text(90)

Code
distance |>
  ggplot(aes(x=interaction(group,target_cell),
             y=distance_to_annotation_with_epithelium_um,
             color=target_cell)) +
  geom_boxplot(outlier.shape = NA) +
  geom_point(position = position_jitterdodge())+
  theme_pubr()+
  scale_color_lancet()+
  facet_grid(~tissue*layer, scales = "free")+
  rotate_x_text(45)

Code
distance |>
  filter(target_cell=="CD4") |>
  ggplot(aes(x=group,
             y=distance_to_annotation_with_epithelium_um,
             color= group))+
  geom_boxplot(outlier.shape = NA)+
  geom_point(position = position_jitterdodge(), alpha = 0.3) +
  theme_pubr()+
  labs(title = "CD4+ Cells Only") +
  scale_color_npg()

Code
distance |>
  ggplot(aes(x=group,
             y=(distance_to_annotation_with_epithelium_um+0.1),
             color=group))+
  geom_boxplot(outlier.shape = NA)+
  geom_point(position = position_jitterdodge())+
  theme_pubr()+
  scale_color_npg()+
  facet_grid(tissue~target_cell)+
  scale_y_log10()+
  rotate_x_text(45)

Code
distance |>
  ggplot(aes(x=group,
             y=distance_to_annotation_with_epithelium_um+0.1,
             color=group))+
  geom_boxplot(outlier.shape = NA)+
  geom_point(position = position_jitterdodge())+
  theme_pubr()+
  scale_color_npg()+
  facet_grid(tissue~target_cell)+
  scale_y_log10()+
  rotate_x_text(45)

looking at mean

Code
# why bother taking a mean here?
mean_dist <- distance |>
  group_by(condition, group, layer, donor, tissue, target_cell) |>
  summarize(mean_distance_to_annotation_with_epithelium_um = mean(distance_to_annotation_with_epithelium_um))

mean_dist |> 
  ggplot(aes(x=layer,
             y=mean_distance_to_annotation_with_epithelium_um,
             color= interaction(group,condition)))+
  geom_boxplot(outlier.shape = NA)+
  geom_point(position = position_jitterdodge())+
  theme_pubr()+
  scale_color_npg()+
  facet_wrap(~target_cell, scales = "free")

Code
mean_dist |> 
  ggplot(aes(x=layer,
             y=mean_distance_to_annotation_with_epithelium_um+1,
             color=group))+
  geom_boxplot(outlier.shape = NA)+
  geom_point(position = position_jitterdodge())+
  theme_pubr()+
  scale_color_npg()+
  facet_grid(tissue*condition~target_cell)+
  scale_y_log10()+
  rotate_x_text(45)

Code
mean_dist |> 
  ggplot(aes(x=group,
             y=mean_distance_to_annotation_with_epithelium_um+1,
             color=layer)) +
  geom_boxplot(outlier.shape = NA) +
  geom_point(position = position_jitterdodge()) +
  theme_pubr()+
  scale_color_jco()+
  facet_grid(tissue*condition~target_cell)+
  scale_y_log10()

modeling

we can also make models to investigate this data:

Code
glans <- mean_dist |> 
  filter(tissue == 'Glans')

model_glans <- lme4::lmer(mean_distance_to_annotation_with_epithelium_um ~ condition*group*layer*target_cell+(1|donor), 
                          data = glans)
summary(model_glans)
Linear mixed model fit by REML ['lmerMod']
Formula: mean_distance_to_annotation_with_epithelium_um ~ condition *  
    group * layer * target_cell + (1 | donor)
   Data: glans

REML criterion at convergence: 5730.9

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-2.9514 -0.4030  0.0035  0.3994  7.9078 

Random effects:
 Groups   Name        Variance Std.Dev.
 donor    (Intercept) 2309     48.05   
 Residual             4413     66.43   
Number of obs: 546, groups:  donor, 39

Fixed effects:
                                                                                  Estimate
(Intercept)                                                                        123.297
conditionUncircumcised                                                             141.945
groupNon infected                                                                   65.960
layerEpithelium                                                                    -57.125
target_cellCD3                                                                      62.306
target_cellCD3+CCR10                                                                19.173
target_cellCD4                                                                      38.195
target_cellCD4+CCR10                                                                94.855
target_cellCD4+CD3                                                                  63.890
target_cellCD4+CD3+CCR10                                                            39.901
conditionUncircumcised:groupNon infected                                          -148.805
conditionUncircumcised:layerEpithelium                                            -190.897
groupNon infected:layerEpithelium                                                  -41.876
conditionUncircumcised:target_cellCD3                                              -70.061
conditionUncircumcised:target_cellCD3+CCR10                                        -85.649
conditionUncircumcised:target_cellCD4                                               11.181
conditionUncircumcised:target_cellCD4+CCR10                                        -89.778
conditionUncircumcised:target_cellCD4+CD3                                          -11.632
conditionUncircumcised:target_cellCD4+CD3+CCR10                                   -102.556
groupNon infected:target_cellCD3                                                  -104.067
groupNon infected:target_cellCD3+CCR10                                             -68.044
groupNon infected:target_cellCD4                                                   -72.287
groupNon infected:target_cellCD4+CCR10                                            -121.251
groupNon infected:target_cellCD4+CD3                                               -77.197
groupNon infected:target_cellCD4+CD3+CCR10                                         -79.722
layerEpithelium:target_cellCD3                                                     -28.406
layerEpithelium:target_cellCD3+CCR10                                                 8.658
layerEpithelium:target_cellCD4                                                      -9.968
layerEpithelium:target_cellCD4+CCR10                                               -97.563
layerEpithelium:target_cellCD4+CD3                                                 -49.681
layerEpithelium:target_cellCD4+CD3+CCR10                                           -15.259
conditionUncircumcised:groupNon infected:layerEpithelium                           201.761
conditionUncircumcised:groupNon infected:target_cellCD3                            -51.337
conditionUncircumcised:groupNon infected:target_cellCD3+CCR10                       96.144
conditionUncircumcised:groupNon infected:target_cellCD4                              8.424
conditionUncircumcised:groupNon infected:target_cellCD4+CCR10                      167.294
conditionUncircumcised:groupNon infected:target_cellCD4+CD3+CCR10                  119.120
conditionUncircumcised:layerEpithelium:target_cellCD3                              108.185
conditionUncircumcised:layerEpithelium:target_cellCD3+CCR10                        154.365
conditionUncircumcised:layerEpithelium:target_cellCD4                               19.328
conditionUncircumcised:layerEpithelium:target_cellCD4+CCR10                        158.933
conditionUncircumcised:layerEpithelium:target_cellCD4+CD3                         -152.079
conditionUncircumcised:layerEpithelium:target_cellCD4+CD3+CCR10                    158.680
groupNon infected:layerEpithelium:target_cellCD3                                   149.559
groupNon infected:layerEpithelium:target_cellCD3+CCR10                              54.193
groupNon infected:layerEpithelium:target_cellCD4                                    12.855
groupNon infected:layerEpithelium:target_cellCD4+CCR10                              47.127
groupNon infected:layerEpithelium:target_cellCD4+CD3                                56.979
groupNon infected:layerEpithelium:target_cellCD4+CD3+CCR10                          58.460
conditionUncircumcised:groupNon infected:layerEpithelium:target_cellCD3+CCR10     -187.747
conditionUncircumcised:groupNon infected:layerEpithelium:target_cellCD4            -46.039
conditionUncircumcised:groupNon infected:layerEpithelium:target_cellCD4+CD3+CCR10 -203.010
                                                                                  Std. Error
(Intercept)                                                                           35.771
conditionUncircumcised                                                                45.365
groupNon infected                                                                     42.711
layerEpithelium                                                                       41.507
target_cellCD3                                                                        40.375
target_cellCD3+CCR10                                                                  37.286
target_cellCD4                                                                        38.773
target_cellCD4+CCR10                                                                  48.086
target_cellCD4+CD3                                                                    40.193
target_cellCD4+CD3+CCR10                                                              37.446
conditionUncircumcised:groupNon infected                                              55.364
conditionUncircumcised:layerEpithelium                                                59.428
groupNon infected:layerEpithelium                                                     59.472
conditionUncircumcised:target_cellCD3                                                 55.219
conditionUncircumcised:target_cellCD3+CCR10                                           47.908
conditionUncircumcised:target_cellCD4                                                 50.784
conditionUncircumcised:target_cellCD4+CCR10                                           57.154
conditionUncircumcised:target_cellCD4+CD3                                             68.721
conditionUncircumcised:target_cellCD4+CD3+CCR10                                       48.033
groupNon infected:target_cellCD3                                                      84.310
groupNon infected:target_cellCD3+CCR10                                                47.840
groupNon infected:target_cellCD4                                                      49.079
groupNon infected:target_cellCD4+CCR10                                                57.409
groupNon infected:target_cellCD4+CD3                                                  68.506
groupNon infected:target_cellCD4+CD3+CCR10                                            47.988
layerEpithelium:target_cellCD3                                                        53.136
layerEpithelium:target_cellCD3+CCR10                                                  46.769
layerEpithelium:target_cellCD4                                                        50.415
layerEpithelium:target_cellCD4+CCR10                                                  87.463
layerEpithelium:target_cellCD4+CD3                                                    55.594
layerEpithelium:target_cellCD4+CD3+CCR10                                              47.044
conditionUncircumcised:groupNon infected:layerEpithelium                              83.734
conditionUncircumcised:groupNon infected:target_cellCD3                              106.472
conditionUncircumcised:groupNon infected:target_cellCD3+CCR10                         63.515
conditionUncircumcised:groupNon infected:target_cellCD4                               65.787
conditionUncircumcised:groupNon infected:target_cellCD4+CCR10                         72.447
conditionUncircumcised:groupNon infected:target_cellCD4+CD3+CCR10                     63.626
conditionUncircumcised:layerEpithelium:target_cellCD3                                 78.279
conditionUncircumcised:layerEpithelium:target_cellCD3+CCR10                           66.981
conditionUncircumcised:layerEpithelium:target_cellCD4                                 71.853
conditionUncircumcised:layerEpithelium:target_cellCD4+CCR10                          101.601
conditionUncircumcised:layerEpithelium:target_cellCD4+CD3                            116.820
conditionUncircumcised:layerEpithelium:target_cellCD4+CD3+CCR10                       67.360
groupNon infected:layerEpithelium:target_cellCD3                                      97.340
groupNon infected:layerEpithelium:target_cellCD3+CCR10                                66.828
groupNon infected:layerEpithelium:target_cellCD4                                      69.703
groupNon infected:layerEpithelium:target_cellCD4+CCR10                               110.742
groupNon infected:layerEpithelium:target_cellCD4+CD3                                  96.500
groupNon infected:layerEpithelium:target_cellCD4+CD3+CCR10                            67.174
conditionUncircumcised:groupNon infected:layerEpithelium:target_cellCD3+CCR10         94.775
conditionUncircumcised:groupNon infected:layerEpithelium:target_cellCD4               98.925
conditionUncircumcised:groupNon infected:layerEpithelium:target_cellCD4+CD3+CCR10     95.216
                                                                                  t value
(Intercept)                                                                         3.447
conditionUncircumcised                                                              3.129
groupNon infected                                                                   1.544
layerEpithelium                                                                    -1.376
target_cellCD3                                                                      1.543
target_cellCD3+CCR10                                                                0.514
target_cellCD4                                                                      0.985
target_cellCD4+CCR10                                                                1.973
target_cellCD4+CD3                                                                  1.590
target_cellCD4+CD3+CCR10                                                            1.066
conditionUncircumcised:groupNon infected                                           -2.688
conditionUncircumcised:layerEpithelium                                             -3.212
groupNon infected:layerEpithelium                                                  -0.704
conditionUncircumcised:target_cellCD3                                              -1.269
conditionUncircumcised:target_cellCD3+CCR10                                        -1.788
conditionUncircumcised:target_cellCD4                                               0.220
conditionUncircumcised:target_cellCD4+CCR10                                        -1.571
conditionUncircumcised:target_cellCD4+CD3                                          -0.169
conditionUncircumcised:target_cellCD4+CD3+CCR10                                    -2.135
groupNon infected:target_cellCD3                                                   -1.234
groupNon infected:target_cellCD3+CCR10                                             -1.422
groupNon infected:target_cellCD4                                                   -1.473
groupNon infected:target_cellCD4+CCR10                                             -2.112
groupNon infected:target_cellCD4+CD3                                               -1.127
groupNon infected:target_cellCD4+CD3+CCR10                                         -1.661
layerEpithelium:target_cellCD3                                                     -0.535
layerEpithelium:target_cellCD3+CCR10                                                0.185
layerEpithelium:target_cellCD4                                                     -0.198
layerEpithelium:target_cellCD4+CCR10                                               -1.115
layerEpithelium:target_cellCD4+CD3                                                 -0.894
layerEpithelium:target_cellCD4+CD3+CCR10                                           -0.324
conditionUncircumcised:groupNon infected:layerEpithelium                            2.410
conditionUncircumcised:groupNon infected:target_cellCD3                            -0.482
conditionUncircumcised:groupNon infected:target_cellCD3+CCR10                       1.514
conditionUncircumcised:groupNon infected:target_cellCD4                             0.128
conditionUncircumcised:groupNon infected:target_cellCD4+CCR10                       2.309
conditionUncircumcised:groupNon infected:target_cellCD4+CD3+CCR10                   1.872
conditionUncircumcised:layerEpithelium:target_cellCD3                               1.382
conditionUncircumcised:layerEpithelium:target_cellCD3+CCR10                         2.305
conditionUncircumcised:layerEpithelium:target_cellCD4                               0.269
conditionUncircumcised:layerEpithelium:target_cellCD4+CCR10                         1.564
conditionUncircumcised:layerEpithelium:target_cellCD4+CD3                          -1.302
conditionUncircumcised:layerEpithelium:target_cellCD4+CD3+CCR10                     2.356
groupNon infected:layerEpithelium:target_cellCD3                                    1.536
groupNon infected:layerEpithelium:target_cellCD3+CCR10                              0.811
groupNon infected:layerEpithelium:target_cellCD4                                    0.184
groupNon infected:layerEpithelium:target_cellCD4+CCR10                              0.426
groupNon infected:layerEpithelium:target_cellCD4+CD3                                0.590
groupNon infected:layerEpithelium:target_cellCD4+CD3+CCR10                          0.870
conditionUncircumcised:groupNon infected:layerEpithelium:target_cellCD3+CCR10      -1.981
conditionUncircumcised:groupNon infected:layerEpithelium:target_cellCD4            -0.465
conditionUncircumcised:groupNon infected:layerEpithelium:target_cellCD4+CD3+CCR10  -2.132
fit warnings:
fixed-effect model matrix is rank deficient so dropping 4 columns / coefficients
Code
a <- pairs(lsmeans(model_glans, ~ layer))
b <- pairs(lsmeans(model_glans, ~ group))
c <- pairs(lsmeans(model_glans, ~ target_cell))
d <- pairs(lsmeans(model_glans, ~ condition))
b.a.c.d <- pairs(lsmeans(model_glans, ~ group | layer | target_cell |condition))
d.a.c.b <- pairs(lsmeans(model_glans, ~  condition| layer | target_cell | group))
c.d.b.a <- pairs(lsmeans(model_glans, ~  target_cell | condition | group | layer ))

GlansBigModel<-rbind(a,b,c, b.a.c.d,d.a.c.b,adjust="fdr")

table <- GlansBigModel |>
  data.frame(stringsAsFactors = FALSE) |>
  mutate(p.value = round(p.value, 5)) |>
  mutate_at(c('estimate', 'SE', 'df', 't.ratio'), function(x){round(x, 2)}) |>
  rename(`p value` = p.value, `t-ratio` = t.ratio, `d.f.` = df) |>
  gt() |>
  cols_align('center') |>
  tab_source_note(
    source_note = "P value adjustment: FDR"
  ) |>
  tab_style(
    style = cell_text(weight = "bold"),
    locations = cells_body(
      rows = `p value` < 0.05)
  ) |>
  tab_header(
    title = md("**GlansBigModel**")
  ) |>
  gt:::as.tags.gt_tbl()

table
GlansBigModel
layer target_cell condition group contrast estimate SE d.f. t-ratio p value
. . . . Connective - Epithelium NA NA NA NA NA
. . . . 4h - Non infected NA NA NA NA NA
. . . . CCR10 - CD3 NA NA NA NA NA
. . . . CCR10 - (CD3+CCR10) 0.64 11.94 462.67 0.05 0.97553
. . . . CCR10 - CD4 -7.05 12.51 463.56 -0.56 0.91842
. . . . CCR10 - (CD4+CCR10) NA NA NA NA NA
. . . . CCR10 - (CD4+CD3) NA NA NA NA NA
. . . . CCR10 - (CD4+CD3+CCR10) 0.18 12.02 462.86 0.01 0.98815
. . . . CD3 - (CD3+CCR10) NA NA NA NA NA
. . . . CD3 - CD4 NA NA NA NA NA
. . . . CD3 - (CD4+CCR10) NA NA NA NA NA
. . . . CD3 - (CD4+CD3) NA NA NA NA NA
. . . . CD3 - (CD4+CD3+CCR10) NA NA NA NA NA
. . . . (CD3+CCR10) - CD4 -7.69 8.66 459.77 -0.89 0.84355
. . . . (CD3+CCR10) - (CD4+CCR10) NA NA NA NA NA
. . . . (CD3+CCR10) - (CD4+CD3) NA NA NA NA NA
. . . . (CD3+CCR10) - (CD4+CD3+CCR10) -0.46 7.96 457.78 -0.06 0.97553
. . . . CD4 - (CD4+CCR10) NA NA NA NA NA
. . . . CD4 - (CD4+CD3) NA NA NA NA NA
. . . . CD4 - (CD4+CD3+CCR10) 7.23 8.74 458.99 0.83 0.84823
. . . . (CD4+CCR10) - (CD4+CD3) NA NA NA NA NA
. . . . (CD4+CCR10) - (CD4+CD3+CCR10) NA NA NA NA NA
. . . . (CD4+CD3) - (CD4+CD3+CCR10) NA NA NA NA NA
Connective CCR10 Circumcised . 4h - Non infected -65.96 42.73 463.40 -1.54 0.50733
Epithelium CCR10 Circumcised . 4h - Non infected -24.08 41.40 461.88 -0.58 0.91842
Connective CD3 Circumcised . 4h - Non infected 38.11 71.69 463.32 0.53 0.91842
Epithelium CD3 Circumcised . 4h - Non infected NA NA NA NA NA
Connective CD3+CCR10 Circumcised . 4h - Non infected 2.08 21.55 457.12 0.10 0.97553
Epithelium CD3+CCR10 Circumcised . 4h - Non infected -10.23 21.55 457.12 -0.47 0.93785
Connective CD4 Circumcised . 4h - Non infected 6.33 24.06 458.71 0.26 0.97553
Epithelium CD4 Circumcised . 4h - Non infected 35.35 28.01 460.12 1.26 0.56038
Connective CD4+CCR10 Circumcised . 4h - Non infected 55.29 38.59 460.82 1.43 0.51500
Epithelium CD4+CCR10 Circumcised . 4h - Non infected 50.04 83.75 463.51 0.60 0.91842
Connective CD4+CD3 Circumcised . 4h - Non infected 11.24 52.83 463.44 0.21 0.97553
Epithelium CD4+CD3 Circumcised . 4h - Non infected -3.87 56.83 462.43 -0.07 0.97553
Connective CD4+CD3+CCR10 Circumcised . 4h - Non infected 13.76 21.88 457.53 0.63 0.91842
Epithelium CD4+CD3+CCR10 Circumcised . 4h - Non infected -2.82 22.53 458.00 -0.13 0.97553
Connective CCR10 Uncircumcised . 4h - Non infected 82.85 35.25 465.86 2.35 0.17248
Epithelium CCR10 Uncircumcised . 4h - Non infected -77.04 47.67 460.47 -1.62 0.48031
Connective CD3 Uncircumcised . 4h - Non infected 238.25 54.96 459.88 4.33 0.00032
Epithelium CD3 Uncircumcised . 4h - Non infected -71.20 55.46 462.68 -1.28 0.56038
Connective CD3+CCR10 Uncircumcised . 4h - Non infected 54.74 23.10 463.50 2.37 0.17248
Epithelium CD3+CCR10 Uncircumcised . 4h - Non infected 28.41 23.10 463.50 1.23 0.56414
Connective CD4 Uncircumcised . 4h - Non infected 146.71 26.41 462.56 5.56 0.00000
Epithelium CD4 Uncircumcised . 4h - Non infected 20.01 27.77 463.84 0.72 0.90944
Connective CD4+CCR10 Uncircumcised . 4h - Non infected 36.80 27.61 464.51 1.33 0.56038
Epithelium CD4+CCR10 Uncircumcised . 4h - Non infected NA NA NA NA NA
Connective CD4+CD3 Uncircumcised . 4h - Non infected NA NA NA NA NA
Epithelium CD4+CD3 Uncircumcised . 4h - Non infected NA NA NA NA NA
Connective CD4+CD3+CCR10 Uncircumcised . 4h - Non infected 43.45 23.10 463.50 1.88 0.29899
Epithelium CD4+CD3+CCR10 Uncircumcised . 4h - Non infected 28.11 24.01 459.53 1.17 0.59446
Connective CCR10 . 4h Circumcised - Uncircumcised -141.94 45.38 465.37 -3.13 0.02527
Epithelium CCR10 . 4h Circumcised - Uncircumcised 48.95 44.40 461.11 1.10 0.63592
Connective CD3 . 4h Circumcised - Uncircumcised -71.88 38.25 411.65 -1.88 0.29899
Epithelium CD3 . 4h Circumcised - Uncircumcised 10.83 40.86 435.71 0.27 0.97553
Connective CD3+CCR10 . 4h Circumcised - Uncircumcised -56.30 26.78 208.49 -2.10 0.24810
Epithelium CD3+CCR10 . 4h Circumcised - Uncircumcised -19.76 26.78 208.49 -0.74 0.90944
Connective CD4 . 4h Circumcised - Uncircumcised -153.13 31.62 309.39 -4.84 0.00005
Epithelium CD4 . 4h Circumcised - Uncircumcised 18.44 34.07 353.37 0.54 0.91842
Connective CD4+CCR10 . 4h Circumcised - Uncircumcised -52.17 41.19 440.00 -1.27 0.56038
Epithelium CD4+CCR10 . 4h Circumcised - Uncircumcised -20.20 73.99 491.73 -0.27 0.97553
Connective CD4+CD3 . 4h Circumcised - Uncircumcised NA NA NA NA NA
Epithelium CD4+CD3 . 4h Circumcised - Uncircumcised NA NA NA NA NA
Connective CD4+CD3+CCR10 . 4h Circumcised - Uncircumcised -39.39 27.04 214.08 -1.46 0.51500
Epithelium CD4+CD3+CCR10 . 4h Circumcised - Uncircumcised -7.17 27.67 226.97 -0.26 0.97553
Connective CCR10 . Non infected Circumcised - Uncircumcised 6.86 38.35 411.97 0.18 0.97553
Epithelium CCR10 . Non infected Circumcised - Uncircumcised -4.00 50.64 483.16 -0.08 0.97553
Connective CD3 . Non infected Circumcised - Uncircumcised 128.26 84.90 487.40 1.51 0.50733
Epithelium CD3 . Non infected Circumcised - Uncircumcised NA NA NA NA NA
Connective CD3+CCR10 . Non infected Circumcised - Uncircumcised -3.63 27.43 221.39 -0.13 0.97553
Epithelium CD3+CCR10 . Non infected Circumcised - Uncircumcised 18.88 27.43 221.39 0.69 0.91582
Connective CD4 . Non infected Circumcised - Uncircumcised -12.74 27.43 221.39 -0.46 0.93785
Epithelium CD4 . Non infected Circumcised - Uncircumcised 3.10 29.44 264.69 0.11 0.97553
Connective CD4+CCR10 . Non infected Circumcised - Uncircumcised -70.66 32.32 321.57 -2.19 0.22795
Epithelium CD4+CCR10 . Non infected Circumcised - Uncircumcised NA NA NA NA NA
Connective CD4+CD3 . Non infected Circumcised - Uncircumcised 18.49 61.08 493.77 0.30 0.97553
Epithelium CD4+CD3 . Non infected Circumcised - Uncircumcised 159.71 84.91 487.44 1.88 0.29899
Connective CD4+CD3+CCR10 . Non infected Circumcised - Uncircumcised -9.70 27.43 221.39 -0.35 0.97553
Epithelium CD4+CD3+CCR10 . Non infected Circumcised - Uncircumcised 23.76 28.30 240.49 0.84 0.84823
P value adjustment: FDR
Code
#htmltools::html_print(table)

#write.csv(GlansBigModel,"GlansBigModel.csv",row.names = F,quote = F)

here we can see significant differences between CD3 and CD4 single positive cells in uncircumsized epithelium between infected and non infected– a significant difference was not detected in corresponding circumsized tissue:

Code
distance |>
  filter(layer == 'Connective' & (target_cell == 'CD4' | target_cell == 'CD3') & tissue == 'Glans') |>
  ggplot(aes(x = group,
             y = distance_to_annotation_with_epithelium_um,
             color = group)) +
  geom_boxplot(outlier.shape = NA) +
  geom_jitter(alpha = 0.4) +
  scale_y_log10() +
  stat_compare_means(
    comparisons = list(c('4h', 'Non infected')),
    method = "wilcox.test", 
    label = "p.signif") +
  facet_grid(rows = vars(target_cell), cols = vars(condition), scales = 'free') +
  labs(title = "[not mean] CD4 Single Positive cells in Connective Tissue (Glans)") +
  theme_pubr() + scale_color_lancet() 

Code
mean_dist |>
  filter(layer == 'Connective' & (target_cell == 'CD4' | target_cell == 'CD3') & tissue == 'Glans') |>
  ggplot(aes(x = group,
             y = mean_distance_to_annotation_with_epithelium_um,
             color = group)) +
  geom_boxplot(outlier.shape = NA) +
  geom_jitter(alpha = 0.4) +
  scale_y_log10() +
  stat_compare_means(
    comparisons = list(c('4h', 'Non infected')),
    method = "wilcox.test", 
    label = "p.signif") +
  facet_grid(rows = vars(target_cell), cols = vars(condition), scales = 'free') +
  labs(title = "[mean] CD4 Single Positive cells in Connective Tissue (Glans)") +
  theme_pubr() + scale_color_lancet()  

Code
mean_dist |>
  filter(layer == 'Epithelium' & target_cell == 'CD4' & group == '4h') |>
  ggplot(aes(x = condition,
             y = mean_distance_to_annotation_with_epithelium_um,
             color = condition)) +
  geom_boxplot(outlier.shape = NA) +
  geom_jitter() +
  scale_y_log10() +
  theme_pubr() + scale_color_lancet() 

Code
#Check other combinations
pairs(lsmeans(model_glans, ~ condition| group | target_cell), adjust="fdr")
group = 4h, target_cell = CCR10:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised   -46.50 33.6 344  -1.382  0.1679

group = Non infected, target_cell = CCR10:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised     1.43 33.6 344   0.042  0.9661

group = 4h, target_cell = CD3:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised   -30.53 30.2 277  -1.011  0.3128

group = Non infected, target_cell = CD3:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised   nonEst   NA  NA      NA      NA

group = 4h, target_cell = CD3+CCR10:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised   -38.03 21.9 108  -1.738  0.0850

group = Non infected, target_cell = CD3+CCR10:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised     7.62 22.3 114   0.342  0.7333

group = 4h, target_cell = CD4:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised   -67.34 25.8 183  -2.613  0.0097

group = Non infected, target_cell = CD4:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised    -4.82 23.0 126  -0.210  0.8340

group = 4h, target_cell = CD4+CCR10:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised   -36.18 43.7 457  -0.829  0.4077

group = Non infected, target_cell = CD4+CCR10:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised   nonEst   NA  NA      NA      NA

group = 4h, target_cell = CD4+CD3:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised   nonEst   NA  NA      NA      NA

group = Non infected, target_cell = CD4+CD3:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised    89.10 54.3 488   1.641  0.1014

group = 4h, target_cell = CD4+CD3+CCR10:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised   -23.28 22.2 114  -1.047  0.2974

group = Non infected, target_cell = CD4+CD3+CCR10:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised     7.03 22.6 119   0.311  0.7562

Results are averaged over the levels of: layer 
Degrees-of-freedom method: kenward-roger 
Code
pairs(lsmeans(model_glans, ~ condition | group), adjust="fdr")
group = 4h:
 contrast                    estimate SE df z.ratio p.value
 Circumcised - Uncircumcised   nonEst NA NA      NA      NA

group = Non infected:
 contrast                    estimate SE df z.ratio p.value
 Circumcised - Uncircumcised   nonEst NA NA      NA      NA

Results are averaged over the levels of: layer, target_cell 
Degrees-of-freedom method: kenward-roger 
Code
shaft <- mean_dist |> 
  filter(tissue == 'Shaft')


model_shaft <- lme4::lmer(mean_distance_to_annotation_with_epithelium_um ~ condition*group*layer*target_cell+(1|donor), data = shaft)

e <- pairs(lsmeans(model_shaft, ~ layer))
f <- pairs(lsmeans(model_shaft, ~ group))
g <- pairs(lsmeans(model_shaft, ~ target_cell))
h <- pairs(lsmeans(model_shaft, ~ condition))
f.e.g.h <- pairs(lsmeans(model_shaft, ~ group | layer | target_cell |condition))
e.g.h.f <- pairs(lsmeans(model_shaft, ~  condition| layer | target_cell | group))

ShaftBigModel<-rbind(e,f,g,f.e.g.h,e.g.h.f,adjust="fdr")


table <- ShaftBigModel |>
  data.frame(stringsAsFactors = FALSE) |>
  mutate(p.value = round(p.value, 5)) |>
  mutate_at(c('estimate', 'SE', 'df', 't.ratio'), function(x){round(x, 2)}) |>
  rename(`p value` = p.value, `t-ratio` = t.ratio, `d.f.` = df) |>
  gt() |>
  cols_align('center') |>
  tab_source_note(
    source_note = "P value adjustment: FDR"
  ) |>
  tab_style(
    style = cell_text(weight = "bold"),
    locations = cells_body(
      rows = `p value` < 0.05)
  ) |>
  tab_header(
    title = md("**ShaftBigModel**")
  ) |>
  gt:::as.tags.gt_tbl()

#htmltools::html_print(table)

#write.csv(ShaftBigModel,"ShaftBigModel.csv",row.names = F,quote = F)

#Check other combinations
pairs(lsmeans(model_shaft, ~ condition| group | layer | target_cell),adjust="fdr")
group = 4h, layer = Connective, target_cell = CCR10:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised -21.0713 28.5 573  -0.738  0.4608

group = Non infected, layer = Connective, target_cell = CCR10:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised  10.1754 20.6 455   0.493  0.6220

group = 4h, layer = Epithelium, target_cell = CCR10:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised   3.0571 26.4 557   0.116  0.9080

group = Non infected, layer = Epithelium, target_cell = CCR10:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised  18.6888 27.7 567   0.675  0.5002

group = 4h, layer = Connective, target_cell = CD3:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised  47.8704 25.7 550   1.861  0.0633

group = Non infected, layer = Connective, target_cell = CD3:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised -22.5521 35.5 589  -0.635  0.5256

group = 4h, layer = Epithelium, target_cell = CD3:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised  23.9849 50.1 583   0.479  0.6323

group = Non infected, layer = Epithelium, target_cell = CD3:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised   nonEst   NA  NA      NA      NA

group = 4h, layer = Connective, target_cell = CD3+CCR10:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised -15.0966 16.6 309  -0.907  0.3649

group = Non infected, layer = Connective, target_cell = CD3+CCR10:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised  14.8795 16.9 322   0.878  0.3805

group = 4h, layer = Epithelium, target_cell = CD3+CCR10:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised  -2.1620 16.8 317  -0.129  0.8978

group = Non infected, layer = Epithelium, target_cell = CD3+CCR10:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised  13.9437 17.2 335   0.808  0.4194

group = 4h, layer = Connective, target_cell = CD4:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised  20.0521 16.8 317   1.192  0.2341

group = Non infected, layer = Connective, target_cell = CD4:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised  16.3006 17.1 328   0.954  0.3409

group = 4h, layer = Epithelium, target_cell = CD4:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised  -5.3991 20.6 455  -0.262  0.7936

group = Non infected, layer = Epithelium, target_cell = CD4:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised   4.7744 17.3 339   0.275  0.7832

group = 4h, layer = Connective, target_cell = CD4+CCR10:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised -16.3627 18.1 370  -0.905  0.3662

group = Non infected, layer = Connective, target_cell = CD4+CCR10:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised  26.2832 17.8 357   1.478  0.1402

group = 4h, layer = Epithelium, target_cell = CD4+CCR10:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised  -4.8517 20.9 462  -0.233  0.8162

group = Non infected, layer = Epithelium, target_cell = CD4+CCR10:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised  71.9048 28.5 573   2.520  0.0120

group = 4h, layer = Connective, target_cell = CD4+CD3:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised  19.7154 23.7 523   0.832  0.4059

group = Non infected, layer = Connective, target_cell = CD4+CD3:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised  31.5623 35.5 590   0.890  0.3737

group = 4h, layer = Epithelium, target_cell = CD4+CD3:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised   0.0892 33.0 587   0.003  0.9978

group = Non infected, layer = Epithelium, target_cell = CD4+CD3:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised  -2.2759 35.5 589  -0.064  0.9489

group = 4h, layer = Connective, target_cell = CD4+CD3+CCR10:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised   1.3707 16.6 309   0.082  0.9344

group = Non infected, layer = Connective, target_cell = CD4+CD3+CCR10:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised  13.2897 16.9 322   0.784  0.4334

group = 4h, layer = Epithelium, target_cell = CD4+CD3+CCR10:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised  -0.6495 17.7 352  -0.037  0.9707

group = Non infected, layer = Epithelium, target_cell = CD4+CD3+CCR10:
 contrast                    estimate   SE  df t.ratio p.value
 Circumcised - Uncircumcised  -5.0843 17.5 345  -0.291  0.7715

Degrees-of-freedom method: kenward-roger 
Code
pairs(lsmeans(model_shaft, ~ condition | group | layer),adjust="fdr")
group = 4h, layer = Connective:
 contrast                    estimate   SE    df t.ratio p.value
 Circumcised - Uncircumcised     5.21 11.3  87.3   0.462  0.6452

group = Non infected, layer = Connective:
 contrast                    estimate   SE    df t.ratio p.value
 Circumcised - Uncircumcised    12.85 12.1 113.4   1.060  0.2914

group = 4h, layer = Epithelium:
 contrast                    estimate   SE    df t.ratio p.value
 Circumcised - Uncircumcised     2.01 13.4 161.7   0.150  0.8812

group = Non infected, layer = Epithelium:
 contrast                    estimate   SE    df t.ratio p.value
 Circumcised - Uncircumcised   nonEst   NA    NA      NA      NA

Results are averaged over the levels of: target_cell 
Degrees-of-freedom method: kenward-roger 
Code
#Data_1_Dist_MeanTotals<-aggregate(Total.Cells/Area.mm.2~condition+group+Tissue+Donor+layer+target_ce#ll, data = Data_1_Dist,mean)